
package com.kommii.mongodb_utils;

import java.io.InputStream;
import java.util.Properties;

/**
 * mongodb的配置文件类
 *	@author: zhb
 */
public class MongoDb_Config {
	/*
	 * mongodb 服务器的ip
	 */
	private static String dbServerIP;
	/*
	 * mongodb 服务器的端口
	 */
    private static int dbServerPort;
    /*
     * mongodb 数据库名称
     */
    private static String dbName;
    /*
     *  mongodb 数据库 用户名
     */
    private static String dbUserName;
    /*
     *  mongodb 数据库 密码
     */
    private static String dbPassword;
    
    /*
     * 
     */
    private static String connectionDescriptor=null;
    
    /*
     *  每个主机对 mongodb 服务器的最大连接数
     */
    private static int connectionsPerHost;
    
    /*
     * 每个连接所负载的线程队列数
     */
    private static int threadsAllowedToBlockForConnectionMultiplier;
    
    /*
     * 连接超时时长
     */
    private static int connectTimeout;
    /*
     * 是否自动重连
     */
    private static boolean autoConnectRetry=true;
    
	static{
		try{
			Properties prop = new Properties();
			InputStream is = MongoDb_Config.class.getClassLoader().getResourceAsStream("mongodb_config.properties");
			prop.load(is);
			dbServerIP=prop.getProperty("dbServerIP");
			dbServerPort=Integer.parseInt(prop.getProperty("dbServerPort"));
			dbName=prop.getProperty("dbName");
			dbUserName=prop.getProperty("dbUserName");
			dbPassword=prop.getProperty("dbPassword");
			connectionDescriptor=prop.getProperty("connectionDescriptor");
			connectionsPerHost=Integer.parseInt((String)prop.getProperty("poolSize"));
			threadsAllowedToBlockForConnectionMultiplier=Integer.parseInt((String)prop.getProperty("threadsAllowedToBlockForConnectionMultiplier"));
			connectTimeout=Integer.parseInt((String)prop.getProperty("connectTimeout"));
			autoConnectRetry=Boolean.parseBoolean((String)prop.getProperty("autoConnectRetry"));
		}catch (Exception e) {
			throw new ExceptionInInitializerError("mongodb server init arguments init error!");
		}
	}

	public static String getDbServerIP() {
		return dbServerIP;
	}

	public static void setDbServerIP(String dbServerIP) {
		MongoDb_Config.dbServerIP = dbServerIP;
	}

	public static int getDbServerPort() {
		return dbServerPort;
	}

	public static void setDbServerPort(int dbServerPort) {
		MongoDb_Config.dbServerPort = dbServerPort;
	}

	public static String getDbName() {
		return dbName;
	}

	public static void setDbName(String dbName) {
		MongoDb_Config.dbName = dbName;
	}

	public static String getDbUserName() {
		return dbUserName;
	}

	public static void setDbUserName(String dbUserName) {
		MongoDb_Config.dbUserName = dbUserName;
	}

	public static String getDbPassword() {
		return dbPassword;
	}

	public static void setDbPassword(String dbPassword) {
		MongoDb_Config.dbPassword = dbPassword;
	}

	public static String getConnectionDescriptor() {
		return connectionDescriptor;
	}

	public static void setConnectionDescriptor(String connectionDescriptor) {
		MongoDb_Config.connectionDescriptor = connectionDescriptor;
	}

	public static int getConnectionsPerHost() {
		return connectionsPerHost;
	}

	public static void setConnectionsPerHost(int connectionsPerHost) {
		MongoDb_Config.connectionsPerHost = connectionsPerHost;
	}

	public static int getThreadsAllowedToBlockForConnectionMultiplier() {
		return threadsAllowedToBlockForConnectionMultiplier;
	}

	public static void setThreadsAllowedToBlockForConnectionMultiplier(
			int threadsAllowedToBlockForConnectionMultiplier) {
		MongoDb_Config.threadsAllowedToBlockForConnectionMultiplier = threadsAllowedToBlockForConnectionMultiplier;
	}

	public static int getConnectTimeout() {
		return connectTimeout;
	}

	public static void setConnectTimeout(int connectTimeout) {
		MongoDb_Config.connectTimeout = connectTimeout;
	}

	public static boolean isAutoConnectRetry() {
		return autoConnectRetry;
	}

	public static void setAutoConnectRetry(boolean autoConnectRetry) {
		MongoDb_Config.autoConnectRetry = autoConnectRetry;
	}

	
}
